package offer;

import binaryTree.basic.TreeNode;

public class Offer26 {


    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A==null){
            return  false;
        }
        else  if (A.val==B.val&&isSameTree(A,B)){
            return  true;
// 两个可以递归的地方
        }else    return  isSubStructure(A.left,B)||isSubStructure(A.right,B);

    }

    public  boolean  isSameTree(TreeNode  A,TreeNode B){
        if (A==null&&B==null){
            return  true;
        }
        if (A==null&&B!=null||A!=null&&B==null){
            return  false;
        }
        return A.val==B.val&&isSameTree(A.left,B.left)&&isSameTree(A.right,B.right);

    }
}
